#ifndef RP2KEYFRAMECONTROLLER_H
#define RP2KEYFRAMECONTROLLER_H

#include "Rp2Controller.h"
#include "Rp2FloatArray.h"
#include "Rp2QuaternionArray.h"
#include "Rp2Vector3Array.h"

namespace Rp2
{

class KeyframeController : public Controller
{
	RP2_DECLARE_RTTI;
	RP2_DECLARE_NAME_ID;

public:
	KeyframeController();
	virtual ~KeyframeController();

	FloatArrayPtr TranslationTimes;
	Vector3fArrayPtr TranslationData;

	FloatArrayPtr RotationTimes;
	QuaternionfArrayPtr RotationData;

	FloatArrayPtr ScaleTimes;
	FloatArrayPtr ScaleData;

	virtual bool Update(double dAppTime);

protected:
	static void GetKeyInfo(float fCtrlTime, int iQuantity, float* afTime,
		int& riLastIndex, float& rfNormTime, int& ri0, int& ri1);

	Vector3f GetTranslate(float fNormTime, int i0, int i1);
	Matrix3f GetRotate(float fNormTime, int i0, int i1);
	float GetScale(float fNormTime, int i0, int i1);

    // Cached indices for the last found pair of keys used for interpolation.
    // For a sequence of times, this guarantees an O(1) lookup.
    int m_iTLastIndex;
    int m_iRLastIndex;
    int m_iSLastIndex;
};

typedef Pointer<KeyframeController> KeyframeControllerPtr;

}

#endif